package com.base.mine.presenter;

import android.app.Activity;

import com.base.commonlib.base.BaseApp;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.CallBackFroPark;
import com.base.commonlib.http.FileBean;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.ResponseT;
import com.base.commonlib.utils.BitmapUtil;
import com.base.commonlib.utils.RxBus2;
import com.base.mine.view.AccountPrivacyView;


import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2020/3/19.
 */

public class AccountPrivacyPresenter extends BasePresenter<AccountPrivacyView>{
    public AccountPrivacyPresenter(AccountPrivacyView view, Activity activity) {
        super(view, activity);
    }

    @Override
    public void start() {
        super.start();
    }

    public void upPicPhoto(String list){

        mView.showPb_mes("正在保存数据");
        FileBean mFileBean = new FileBean("file",BitmapUtil.compressImage(list));
        Disposable enqueue = RealNetWorkUtil.postPics().method("api-auth/user/uploadAvatar").addParams("userId",mUser.getUserId()).addFilePaths(mFileBean)
               .build().enqueueForUpFiles(new CallBackFroPark<ResponseT>() {
                    @Override
                    public void onResponse(ResponseT responseT) throws Exception {
                        mView.hidePb_mes();
                        mView.showMes("保存成功");
                        mView.returnUpPhotoSuccess(responseT.getData().toString());
                        mUser.setAvatar(responseT.getData().toString());
                        BaseApp.saveUser(mUser);
                        RxBus2.getInstance().post(mUser);
                    }

                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                    }

                    @Override
                    public void onNext(ResponseT responseT) {

                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
